This is an R Markdown Notebook. When you execute code within the notebook, the results appear beneath the code.

Load the required libraries. If you don’t have them installed, please do by running install.packages()

library(plotly)
library(stringr)
library(reshape2)
library(dplyr)
library(readr)

Load the NMR binned csv. Just adapt the path to location of your file. You can use autocompletion using the tab key

Binning_Fusarium_sh1 <- read_csv("../../data/Binning_Fusarium_matz_center.csv")
Duplicated column names deduplicated: '-115.03' => '-115.03_1' [146], '702.028' => '702.028_1' [283], '1675.59' => '1675.59_1' [286], '-314.082' => '-314.082_1' [308], '-402.228' => '-402.228_1' [326], '-202.469' => '-202.469_1' [331], '-240.71' => '-240.71_1' [495], '313.821' => '313.821_1' [599], '443.177' => '443.177_1' [614], '-168.964' => '-168.964_1' [628], '-161.33' => '-161.33_1' [637], '-305.105' => '-305.105_1' [661], '65.8555' => '65.8555_1' [730], '281.871' => '281.871_1' [735], '785.014' => '785.014_1' [778], '221.152' => '221.152_1' [803], '141.064' => '141.064_1' [830], '-195.684' => '-195.684_1' [865], '146.084' => '146.084_1' [874], '-49.4336' => '-49.4336_1' [877], '96.0381' => '96.0381_1' [903], '-4.61914' => '-4.61914_1' [921], '-40.5273' => '-40.5273_1' [923], '-57.3506' => '-57.3506_1' [963], '-77.3545' => '-77.3545_1' [965], '-135.034' => '-135.034_1' [982], '-121.533' => '-121.533_1' [986], '-135.883' => '-135.883_1' [1002], '-168.964' => '-168.964_2' [1039], '-21.3008' => '-21.3008_1' [1041], '11.0029' => '11.0029_1' [1055], '134.562' => '134.562_1' [1058], '-200.207' => '-200.207_1' [1066], '52.9902' => '52.9902_1' [1077], '58.3623' => '58.3623_1' [1099], '-0.519531' => '-0.519531_1' [1131], '-130.652' => '-130.652_1' [1138], '158.453' => '158.453_1' [1140], '166.3' => '166.3_1' [1153], '92.4326' => '92.4326_1' [1156], '-10.7686' => '-10.7686_1' [1160], '-36.7812' => '-36.7812_1' [1166], '131.098' => '131.098_1' [1174], '-150.373' => '-150.373_1' [1179], '149.265' => '149.265_1' [1190], '47.6885' => '47.6885_1' [1216], '10.7197' => '10.7197_1' [1225], '-60.6729' => '-60.6729_1' [1232], '-268.419' => '-268.419_1' [1236], '24.998' => '24.998_1' [1253], '-96.9346' => '-96.9346_1' [1264], '207.086' => '207.086_1' [1265], '-87.4629' => '-87.4629_1' [1276], '105.51' => '105.51_1' [1285], '50.2334' => '50.2334_1' [1288], '56.2412' => '56.2412_1' [1293], '-26.1777' => '-26.1777_1' [1314], '-229.471' => '-229.471_1' [1318], '70.3086' => '70.3086_1' [1333], '-63.8535' => '-63.8535_1' [1342], '28.8857' => '28.8857_1' [1343], '86.5664' => '86.5664_1' [1345], '8.95312' => '8.95312_1' [1353], '43.8008' => '43.8008_1' [1354], '-5.4668' => '-5.4668_1' [1355], '-4.61914' => '-4.61914_2' [1361], '62.6035' => '62.6035_1' [1388], '75.8213' => '75.8213_1' [1395], '-67.2471' => '-67.2471_1' [1400], '22.666' => '22.666_1' [1410], '104.309' => '104.309_1' [1414], '19.9795' => '19.9795_1' [1425], '26.3418' => '26.3418_1' [1428], '-10.415' => '-10.415_1' [1431], '-75.5879' => '-75.5879_1' [1440], '-55.584' => '-55.584_1' [1441], '4.64062' => '4.64062_1' [1444], '52.9902' => '52.9902_2' [1456], '-85.625' => '-85.625_1' [1457], '-266.369' => '-266.369_1' [1459], '-126.199' => '-126.199_1' [1472], '65.502' => '65.502_1' [1506], '-126.128' => '-126.128_1' [1508], '-74.7393' => '-74.7393_1' [1523], '-8.29492' => '-8.29492_1' [1540], '-82.0908' => '-82.0908_1' [1544], '-103.721' => '-103.721_1' [1554], '-19.958' => '-19.958_1' [1558], '18.3545' => '18.3545_1' [1572], '-116.373' => '-116.373_1' [1578], '827.072' => '827.072_1' [1602]
── Column specification ───────────────────────────────────────────────────────────────────────────────────────────────────────
cols(
  .default = col_double()
)
ℹ Use `spec()` for the full column specifications.

Lets have a look at the first rows of this file

head(Binning_Fusarium_sh1)

OK. Be sure to have ppm on the columns and fraction numbers as rows. Now we transform the dataframe as a matrix

DTz <- as.matrix(data.frame(Binning_Fusarium_sh1))

Lets have a look at the structure of the file

str(DTz)
 num [1:134, 1:1602] -12215 -13266 -12792 -12116 -12881 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:1602] "X.14393.5" "X358.495" "X.14208.8" "X602.433" ...

Now we’ll remove the row indexes

DTz <- DTz[,-1] 

And we set the matrix row and colnames according to the ones of the df

colnames(DTz) <- colnames(Binning_Fusarium_sh1)[-1]
rownames(DTz) <- rownames(Binning_Fusarium_sh1)

Let’s transform these data in the long form


mtrx.melt <- melt(DTz, id.vars = c('sample', 'ppm'), measure.vars = 'int')
names(mtrx.melt) <- c('sample', 'ppm', 'int')

Now we can plot a quick 3Dplot to have an overview of the data


p <- plot_ly(z = ~DTz) %>% add_surface()

p

OK so now we want to remove the annoying signals corresponding to the solvents. We can check at the colunms name and note their numbers. Example its DMSO > signals at 2.5 ppm I want to delete columns 350,351 and 352.


colnames(DTz)
   [1] "358.495"    "-14208.8"   "602.433"    "-953.72"    "-696.635"   "-713.104"   "-655.849"   "-586.647"   "-556.252"  
  [10] "-456.443"   "-367.592"   "-187.201"   "-35.2256"   "14.4658"    "-106.619"   "358.354"    "129.261"    "339.622"   
  [19] "187.93"     "383.023"    "424.374"    "402.179"    "342.52"     "118.799"    "165.169"    "534.361"    "473.147"   
  [28] "100.421"    "379.064"    "231.26"     "382.67"     "390.162"    "368.179"    "527.223"    "493.435"    "601.23"    
  [37] "27.0488"    "401.118"    "463.322"    "272.895"    "454.628"    "358.637"    "478.591"    "144.246"    "303.572"   
  [46] "444.52"     "131.098"    "138.874"    "215.568"    "112.366"    "222.071"    "175.843"    "208.217"    "67.127"    
  [55] "175.983"    "276.287"    "389.385"    "260.807"    "153.576"    "134.562"    "65.8555"    "200.229"    "341.389"   
  [64] "118.092"    "416.599"    "213.659"    "-26.1777"   "-19.4629"   "215.427"    "214.296"    "81.4766"    "-25.4717"  
  [73] "55.8174"    "-95.0967"   "138.096"    "81.6182"    "313.821"    "35.248"     "64.0176"    "3.50977"    "182.274"   
  [82] "8.1748"     "187.223"    "74.1963"    "26.9072"    "160.928"    "139.651"    "-67.5293"   "85.2227"    "134.42"    
  [91] "129.967"    "-126.199"   "-7.58789"   "-163.804"   "235.36"     "15.8799"    "50.5166"    "98.3701"    "83.668"    
 [100] "-37.6289"   "-328.148"   "-126.411"   "-33.1055"   "-112.839"   "-40.5273"   "22.3125"    "-103.297"   "43.8008"   
 [109] "-217.879"   "75.1855"    "-106.76"    "-161.188"   "10.5781"    "-190.24"    "-218.444"   "-10.9102"   "12.1338"   
 [118] "-67.1055"   "-1.93262"   "-115.03"    "-182.677"   "-282.697"   "-295.421"   "-29.2178"   "-137.509"   "-132.561"  
 [127] "-177.022"   "-5.4668"    "-43.3545"   "-114.96"    "-135.388"   "-185.434"   "7.18555"    "-188.968"   "-176.244"  
 [136] "-231.309"   "-255.201"   "-148.183"   "-16.4941"   "-171.367"   "-18.6855"   "-222.402"   "-103.014"   "-202.469"  
 [145] "-115.03_1"  "-161.684"   "-252.373"   "-80.1826"   "-398.481"   "-320.231"   "-280.789"   "-390.141"   "-185.646"  
 [154] "-305.105"   "-216.041"   "-293.229"   "-293.583"   "-201.196"   "-419.97"    "-213.354"   "16.5166"    "-260.573"  
 [163] "-82.2324"   "-274.074"   "-260.36"    "-207.912"   "-412.053"   "-361.725"   "-345.679"   "-240.71"    "-237.671"  
 [172] "-270.964"   "-179.284"   "-402.228"   "-68.3066"   "-473.055"   "-346.881"   "-147.546"   "-222.897"   "-375.014"  
 [181] "-325.392"   "-122.17"    "-234.631"   "-163.168"   "16.1631"    "-125.28"    "-62.1572"   "37.0146"    "238.611"   
 [190] "240.449"    "220.375"    "-268.419"   "-364.976"   "-150.373"   "-301.005"   "-95.6621"   "26.3418"    "-14.0205"  
 [199] "-138.145"   "11.2852"    "207.086"    "-256.332"   "-63.8535"   "-296.905"   "224.263"    "1341.88"    "548.146"   
 [208] "5301.35"    "5063.42"    "504.744"    "785.014"    "1032.34"    "2084.08"    "1927.37"    "1625.75"    "2876.54"   
 [217] "3343.21"    "2368.95"    "942.149"    "435.189"    "449.114"    "456.819"    "425.646"    "1371.99"    "3039.19"   
 [226] "1787.41"    "3315.29"    "5336.48"    "2003.22"    "1695.31"    "933.172"    "1047.54"    "536.199"    "371.431"   
 [235] "388.678"    "87.6973"    "-13.9492"   "394.757"    "576.915"    "44.3662"    "-174.194"   "141.56"     "4278.17"   
 [244] "-44.1328"   "-158.715"   "-246.365"   "-195.612"   "58.2207"    "-113.829"   "-77.3545"   "15.0322"    "264.482"   
 [253] "160.786"    "177.397"    "336.724"    "116.184"    "186.728"    "-200.065"   "-396.148"   "-254.564"   "-195.4"    
 [262] "173.156"    "-237.176"   "-279.729"   "-324.826"   "-101.529"   "212.316"    "48.5371"    "-82.0908"   "-22.7852"  
 [271] "-255.13"    "-368.581"   "-30.9141"   "-538.935"   "-279.517"   "-169.388"   "-275.629"   "-353.808"   "-3.7002"   
 [280] "42.8115"    "702.028"    "702.028_1"  "443.177"    "1675.59"    "1675.59_1"  "3295.85"    "876.341"    "582.146"   
 [289] "104.309"    "82.6074"    "-288.211"   "-133.196"   "-173.982"   "-404.065"   "-125.351"   "-367.309"   "-435.662"  
 [298] "-228.835"   "-196.249"   "-209.325"   "-294.714"   "1009.94"    "-382.931"   "674.249"    "-253.363"   "-314.082"  
 [307] "-314.082_1" "-392.826"   "-453.687"   "-438.772"   "-55.3711"   "205.106"    "-313.375"   "102.965"    "-49.4336"  
 [316] "-21.3008"   "-333.238"   "-133.55"    "-625.312"   "-491.15"    "-492.493"   "-322.776"   "-440.539"   "-321.504"  
 [325] "-402.228_1" "-431.916"   "-122.735"   "-474.186"   "-516.88"    "-202.469_1" "-203.741"   "-32.3281"   "539.31"    
 [334] "-479.487"   "20389"      "613.671"    "1259.53"    "-1378.61"   "-415.729"   "460.07"     "1321.87"    "45321.9"   
 [343] "43390.2"    "5332.88"    "10040.9"    "28657.8"    "19250.2"    "8769"       "8787.37"    "14597.5"    "29674.7"   
 [352] "102524"     "757484"     "1.90E+07"   "1.18E+06"   "243020"     "51894.9"    "31236"      "16133.4"    "10413.5"   
 [361] "9314.48"    "12067.1"    "2887.78"    "4589.76"    "94192.6"    "23062.5"    "3709.29"    "2056.02"    "2069.94"   
 [370] "2199.86"    "466.433"    "978.765"    "1028.95"    "1126.99"    "497.888"    "511.247"    "869.483"    "625.829"   
 [379] "810.391"    "960.527"    "804.382"    "1169.62"    "986.822"    "234.865"    "547.227"    "166.3"      "220.233"   
 [388] "201.147"    "244.974"    "202.208"    "175.206"    "122.051"    "354.749"    "-44.2734"   "187.294"    "49.8096"   
 [397] "2.37891"    "320.042"    "1342.58"    "8941.33"    "374.541"    "237.41"     "29.0273"    "445.722"    "566.807"   
 [406] "453.779"    "519.164"    "454.274"    "678.49"     "496.615"    "1070.02"    "583.135"    "1236.49"    "2219.8"    
 [415] "7940.13"    "4900.78"    "965.192"    "1429.6"     "1358.49"    "2152.93"    "4612.59"    "1993.96"    "1921.15"   
 [424] "2810.38"    "3361.09"    "4272.38"    "5766.89"    "5625.09"    "8655.61"    "12033.3"    "20393"      "33175.1"   
 [433] "61905.3"    "152525"     "1.02E+06"   "1.46E+06"   "166382"     "60913.6"    "35899.1"    "21488.9"    "14860.4"   
 [442] "10017.4"    "8240.55"    "6283.18"    "6664.39"    "5805.91"    "4730.49"    "3903.4"     "3366.47"    "3749.51"   
 [451] "6450.78"    "9137.55"    "7284.45"    "4554.34"    "3685.05"    "3187.7"     "4872.08"    "4623.83"    "5808.74"   
 [460] "4348.36"    "3160.49"    "3705.55"    "3552.3"     "4774.6"     "4690.84"    "3299.1"     "2635.29"    "2124.16"   
 [469] "3312.32"    "2817.24"    "2975.64"    "2190.11"    "1752.49"    "1780.2"     "1352.62"    "2181.84"    "1490.81"   
 [478] "2415.25"    "1979.75"    "2486.85"    "1079.7"     "928.224"    "635.584"    "645.621"    "294.029"    "1018.91"   
 [487] "3302.57"    "1729.1"     "528.989"    "92.4326"    "309.792"    "591.971"    "180.225"    "-240.71_1"  "147.709"   
 [496] "213.589"    "-230.249"   "420.91"     "4956.76"    "2161.48"    "170.471"    "15.7383"    "5.91309"    "1053.2"    
 [505] "2762.24"    "1944.41"    "212.67"     "-65.9746"   "-134.822"   "-144.012"   "281.871"    "1071.93"    "662.232"   
 [514] "285.052"    "52.4951"    "971.555"    "2295.57"    "1846.15"    "0.258789"   "-119.342"   "76.2461"    "649.438"   
 [523] "1358.14"    "358.849"    "58.3623"    "-59.1885"   "-59.9658"   "57.8672"    "86.7783"    "216.486"    "180.437"   
 [532] "-141.325"   "239.46"     "519.729"    "746.844"    "585.68"     "743.451"    "870.05"     "1033.69"    "3647.23"   
 [541] "6732.18"    "4759.83"    "1569.49"    "1024.22"    "811.31"     "827.991"    "1163.33"    "3082.59"    "3521.62"   
 [550] "895.214"    "509.339"    "689.8"      "150.325"    "96.0381"    "310.711"    "232.815"    "400.978"    "132.653"   
 [559] "18.9199"    "-34.8018"   "141.064"    "656.295"    "690.719"    "1531.81"    "1279.82"    "409.035"    "524.466"   
 [568] "208.57"     "946.531"    "2024.78"    "3222.97"    "2476.95"    "258.403"    "152.304"    "44.6494"    "186.516"   
 [577] "154.354"    "225.464"    "143.468"    "148.981"    "261.584"    "-4.61914"   "169.764"    "341.247"    "600.1"     
 [586] "601.867"    "221.152"    "19.7676"    "172.308"    "-180.839"   "-49.0098"   "-268.489"   "-252.444"   "213.377"   
 [595] "-160.34"    "-402.439"   "-53.3926"   "313.821_1"  "-56.502"    "-38.4072"   "-135.883"   "-456.797"   "-132.277"  
 [604] "-95.0264"   "-185.01"    "116.325"    "187.081"    "115.83"     "103.318"    "2187.71"    "4368.23"    "986.187"   
 [613] "443.177_1"  "329.867"    "97.2393"    "-168.964"   "91.0898"    "29.8047"    "560.939"    "1628.58"    "307.601"   
 [622] "-264.814"   "-161.33"    "-36.4277"   "-116.373"   "696.232"    "-168.964_1" "-129.309"   "-427.745"   "-324.332"  
 [631] "-98.7021"   "56.2412"    "-150.586"   "-101.741"   "-227.562"   "-161.33_1"  "-242.194"   "-195.684"   "1742.31"   
 [640] "1608.15"    "716.52"     "1171.03"    "2055.81"    "1557.68"    "1317.7"     "8813.17"    "2267.93"    "-130.652"  
 [649] "-333.874"   "-376.215"   "-273.791"   "-407.67"    "-413.396"   "-656.344"   "-491.574"   "-314.647"   "-120.049"  
 [658] "-245.658"   "-317.546"   "-305.105_1" "-382.012"   "-447.184"   "-126.128"   "-187.413"   "8.74023"    "-158.148"  
 [667] "998.769"    "-20.3115"   "-374.165"   "-456.655"   "-266.369"   "-39.3965"   "-307.861"   "-252.091"   "-302.207"  
 [676] "-212.365"   "-172.64"    "-139.771"   "415.256"    "1755.18"    "565.676"    "-154.261"   "-55.8662"   "-305.953"  
 [685] "-526.564"   "-29.4297"   "-525.646"   "-156.877"   "2170.53"    "2577.54"    "-167.268"   "-336.984"   "-199.712"  
 [694] "-367.662"   "-478.427"   "-370.772"   "-534.552"   "-194.481"   "-389.857"   "-419.334"   "-210.244"   "-200.207"  
 [703] "-212.224"   "47.6885"    "-432.41"    "-296.41"    "-337.126"   "-198.864"   "-268.914"   "-148.253"   "-381.021"  
 [712] "-215.829"   "-283.192"   "-67.0342"   "38.0049"    "25.7764"    "-212.082"   "-110.224"   "11.0029"    "-355.504"  
 [721] "81.123"     "-232.652"   "-346.668"   "-149.879"   "-152.282"   "173.58"     "-36.71"     "99.7842"    "65.8555_1" 
 [730] "190.828"    "454.84"     "162.129"    "38.5703"    "281.871_1"  "-93.4717"   "457.313"    "555.002"    "708.603"   
 [739] "417.729"    "187.718"    "305.057"    "158.312"    "-72.9014"   "23.5137"    "157.817"    "290"        "441.551"   
 [748] "1382.1"     "175.277"    "224.05"     "461.838"    "494.354"    "152.516"    "217.265"    "381.326"    "682.236"   
 [757] "370.865"    "422.042"    "17.7881"    "64.9365"    "283.073"    "137.46"     "289.576"    "176.479"    "164.108"   
 [766] "213.801"    "199.805"    "492.445"    "486.86"     "696.374"    "511.459"    "629.293"    "498.807"    "625.547"   
 [775] "582.641"    "570.623"    "785.014_1"  "705.775"    "909.28"     "747.339"    "694.678"    "815.833"    "542.35"    
 [784] "244.479"    "371.854"    "193.16"     "-51.2715"   "59.1396"    "-140.689"   "938.049"    "623.497"    "200.865"   
 [793] "6.76172"    "105.51"     "348.245"    "264.978"    "258.475"    "39.3477"    "213.447"    "242.217"    "396.241"   
 [802] "221.152_1"  "430.736"    "1800.98"    "432.361"    "181.215"    "281.518"    "736.947"    "473.854"    "623.709"   
 [811] "1961.87"    "671.917"    "-57.2803"   "95.6143"    "100.986"    "58.4326"    "124.383"    "65.502"     "173.015"   
 [820] "176.267"    "398.009"    "76.9531"    "21.6758"    "113.073"    "107.701"    "64.2295"    "50.2334"    "258.263"   
 [829] "141.064_1"  "433.775"    "1577.19"    "1939.1"     "1895.99"    "2033.47"    "5548.68"    "1346.05"    "528.282"   
 [838] "326.898"    "560.586"    "1979.89"    "10791.3"    "-50.4238"   "196.129"    "62.6035"    "77.165"     "146.084"   
 [847] "-264.531"   "-17.8369"   "-215.122"   "-24.835"    "-227.351"   "-229.471"   "-192.644"   "-113.617"   "-66.2568"  
 [856] "-128.743"   "-339.883"   "-117.575"   "-141.396"   "-1.5791"    "-34.166"    "18.4248"    "-185.504"   "-195.684_1"
 [865] "86.5664"    "-154.12"    "149.265"    "-13.3135"   "50.7285"    "124.171"    "-99.4795"   "-15.0098"   "146.084_1" 
 [874] "-154.474"   "-60.6729"   "-49.4336_1" "-70.8516"   "-62.6523"   "-172.286"   "-37.417"    "-173.417"   "-164.511"  
 [883] "-362.644"   "-172.428"   "-204.519"   "-135.034"   "259.817"    "49.5264"    "1179.65"    "2135.05"    "241.58"    
 [892] "21.3936"    "301.381"    "104.661"    "6.5498"     "201.431"    "410.661"    "648.802"    "388.748"    "223.556"   
 [901] "282.437"    "96.0381_1"  "276.782"    "-100.61"    "-181.97"    "259.676"    "1392.14"    "243.56"     "359.626"   
 [910] "379.913"    "1642.08"    "1792.15"    "1393.27"    "1327.32"    "1154.14"    "390.516"    "-2.56934"   "53.2725"   
 [919] "-162.319"   "-4.61914_1" "-104.993"   "-40.5273_1" "79.0029"    "-179.496"   "72.8525"    "-136.448"   "-291.038"  
 [928] "-8.50684"   "130.392"    "135.057"    "489.335"    "420.062"    "828.769"    "2038.56"    "6233.28"    "6566.77"   
 [937] "1049.52"    "227.302"    "90.5947"    "-19.958"    "7.53906"    "-55.5127"   "-238.66"    "-195.117"   "-103.721"  
 [946] "22.666"     "-16.5645"   "182.981"    "286.254"    "1721.75"    "1833.85"    "896.345"    "327.04"     "-130.723"  
 [955] "128.129"    "-90.6436"   "-5.82031"   "-161.612"   "-57.3506"   "-75.5879"   "-249.334"   "-57.3506_1" "-308.074"  
 [964] "-77.3545_1" "-302.843"   "-190.452"   "-260.502"   "-153.342"   "-63.7832"   "-109.163"   "-121.533"   "-381.799"  
 [973] "-166.914"   "-390.847"   "-124.785"   "-96.0869"   "-111.284"   "-231.238"   "50.8691"    "-117.929"   "-135.034_1"
 [982] "-36.2861"   "-93.3301"   "-179.426"   "-121.533_1" "-340.165"   "-302.631"   "-163.945"   "-70.0039"   "-117.292"  
 [991] "-75.6582"   "-217.454"   "-221.13"    "-33.459"    "-68.3779"   "492.304"    "3623.2"     "216.346"    "-76.9307"  
[1000] "-36.7812"  
 [ reached getOption("max.print") -- omitted 601 entries ]

DTzred <- DTz[,-348:-352]

Now lets plot again …. Does it looks better ?

p <- plot_ly(z = ~DTzred) %>% add_surface()

p

Else repeat the previous step For this execute the following code. Be sure to run it on the previously cleaned object. In this case DTzred Be sure to check again the columns numbers sinsce these have changed

colnames(DTzred)
DTzred <- DTzred[,-348:-352]

Now that you have the cleaned data object lets have a look at the 2d map. Be patient, this one is longer to plot.

p <- plot_ly(mtrx.melt, x = ~sample, y = ~ppm, z = ~int, type = "contour",
             colors = 'YlOrRd',
             autocontour = F,
             contours = list(
               start = 10000,
               end = 1200000,
               size = 5000
             )
            )

p
NA

If you want to plot the map with ppm on the x-axis just reverse the axis order. Play with start value (to fix the noise) and size value to fix the contour space. Change color if you wish by changing the color field. For more info on 2d contour plot with plotly check https://plot.ly/r/contour-plots/


p <- plot_ly(mtrx.melt, x = ~ppm, y = ~sample, z = ~int, type = "contour",
             autocontour = F,
             colors = 'YlOrRd',
             contours = list(
               start = 10000,
               end = 1200000,
               size = 50000
             )
            ) %>% layout(xaxis = list(autorange = "reversed"))

p
NA

When you save the notebook, an HTML file containing the code and output will be saved alongside it (click the Preview button or press Cmd+Shift+K to preview the HTML file).

The preview shows you a rendered HTML copy of the contents of the editor. Consequently, unlike Knit, Preview does not run any R code chunks. Instead, the output of the chunk when it was last run in the editor is displayed.

LS0tCnRpdGxlOiAiTk1SIERhdGEgcGxvdHRlciIKb3V0cHV0OgogIGh0bWxfZG9jdW1lbnQ6CiAgICBkZl9wcmludDogcGFnZWQKICBodG1sX25vdGVib29rOiBkZWZhdWx0CiAgcGRmX2RvY3VtZW50OiBkZWZhdWx0Ci0tLQoKVGhpcyBpcyBhbiBbUiBNYXJrZG93bl0oaHR0cDovL3JtYXJrZG93bi5yc3R1ZGlvLmNvbSkgTm90ZWJvb2suIFdoZW4geW91IGV4ZWN1dGUgY29kZSB3aXRoaW4gdGhlIG5vdGVib29rLCB0aGUgcmVzdWx0cyBhcHBlYXIgYmVuZWF0aCB0aGUgY29kZS4gCgoKTG9hZCB0aGUgcmVxdWlyZWQgbGlicmFyaWVzLiBJZiB5b3UgZG9uJ3QgaGF2ZSB0aGVtIGluc3RhbGxlZCwgcGxlYXNlIGRvIGJ5IHJ1bm5pbmcgaW5zdGFsbC5wYWNrYWdlcygpCgpgYGB7cn0KbGlicmFyeShwbG90bHkpCmxpYnJhcnkoc3RyaW5ncikKbGlicmFyeShyZXNoYXBlMikKbGlicmFyeShkcGx5cikKbGlicmFyeShyZWFkcikKCmBgYAoKCkxvYWQgdGhlIE5NUiBiaW5uZWQgY3N2LiBKdXN0IGFkYXB0IHRoZSBwYXRoIHRvIGxvY2F0aW9uIG9mI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